/* 批量导入物流单号功能 */
var htmlCodes = [
    '<div id="importLogistics" v-cloak>',
    '    <el-dialog title="批量导入物流信息" :visible.sync="dialogVisible">',
    '         <el-row><el-col :span="24"><div class="grid-content bg-purple-dark" v-html="msg"></div></el-col></el-row>',
    '        <el-upload class="upload-demo" action="'+ baseURL +'logistics/erplogistics/importLogistics/"',
    '        :before-upload="beforeUpload"',
    '        :on-success="onSuccess"',
    '        :on-error="onError"',
    '        :file-list="fileList">',
    '        <el-button size="small" type="primary">点击上传</el-button>',
    '        <div slot="tip" class="el-upload__tip">请按照格式上传.xlsx模板文件，没有请点击<el-button type="text" @click="downloadFile">下载</el-button>。</div>',
    '        </el-upload>',
    '    </el-dialog>',
    '</div>'
].join("");

Vue.component('zy-logistics-import', {
    template: htmlCodes,
    data(){
        return {
            dialogVisible: false,
            fileList: [],
            succ: true,
            msg: null
        }
    },
    methods: {
        click: function () {
            this.dialogVisible = true;
        },
        beforeUpload: function (file) {
            var name = file.name;
            var extName = name.substring(name.lastIndexOf(".") + 1, name.length);
            if (extName != 'xlsx'){
                this.$message.warning("请上传.xlsx后缀名文件");
                return false;
            }
        },
        onSuccess: function (data) {
            var self = this;
            var code = data.code;
            if (code != 0){
                self.msg = data.msg;
                self.succ = false;
            }else {
                self.msg = "上传成功";
            }
        },
        onError: function (data) {
            self.msg = "上传失败";
        },
        downloadFile: function () {
            window.open("/statics/js/modules/logistics/template.xlsx");
        },
    }
});
